package my.suveng.chat.export.task.model.domain;

import cn.hutool.core.util.ObjectUtil;
import my.suveng.chat.export.task.config.DateConfig;

import javax.validation.constraints.Pattern;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 导出任务配置中心
 *
 * @author 苏文广
 * 
 * @date 2020/10/10 16:24:13
 */
public class SysExportTask {
    /**
     * 主键
     */
    private Long exportTaskId;

    /**
     * 导出文件名
     */
    private String fileName;

    /**
     * 文件点击下载次数
     */
    private Integer fileDownloadClickTimes;

    /**
     * 文件下载成功次数
     */
    private Integer fileDownloadFinishTimes;

    /**
     * 导出文件url
     */
    private String fileUrl;

    /**
     * 获取数据的查询接口
     */
    private String loadDataInterface;

    /**
     * 获取数据的查询接口的查询参数
     */
    private String loadDataInterfaceParams;

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 修改时间,更新则修改
     */
    private Date modifyTime;

    /**
     * 处理开始时间
     */
    private Date processStartTime;

    /**
     * 处理结束时间
     */
    private Date processEndTime;

    /**
     * 任务状态标记
     */
    private Integer taskStatus;

    /**
     * 任务状态描述
     */
    private String taskStatusRemark;

    /**
     * 0: 不通知, 1: 邮件, 2: 钉钉
     */
    private Integer notifyType;

    /**
     * 通知人
     */
    private String notifyUser;

    /**
     * 是否触达,0:未读,1:已读
     */
    private Integer notified;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String createTimeStart;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String createTimeEnd;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String modifyTimeStart;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String modifyTimeEnd;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String processStartTimeStart;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String processStartTimeEnd;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String processEndTimeStart;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String processEndTimeEnd;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String finishTimeStart;

    /**
     * 时间范围
     */
    @Pattern(regexp = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message = "YYYY-MM-DD HH:mm:SS")
    private String finishTimeEnd;

    /**
     * 查询条件转化
     *
     * @return {@link SysExportTaskExample}
     */
    public SysExportTaskExample toExample() {
        SysExportTaskExample example = new SysExportTaskExample();
        SysExportTaskExample.Criteria criteria = example.createCriteria();
        if (ObjectUtil.isNotEmpty(createTimeStart)) {
            LocalDateTime parse = LocalDateTime.parse(createTimeStart,
                    DateTimeFormatter.ofPattern(DateConfig.DATETIME_FORMAT_PATTERN));
            criteria.andCreateTimeGreaterThanOrEqualTo(Date.from(parse.atZone(ZoneOffset.systemDefault()).toInstant()));
        }

        if (ObjectUtil.isNotEmpty(createTimeEnd)) {
            LocalDateTime parse = LocalDateTime.parse(createTimeEnd,
                    DateTimeFormatter.ofPattern(DateConfig.DATETIME_FORMAT_PATTERN));
            criteria.andCreateTimeLessThanOrEqualTo(Date.from(parse.atZone(ZoneId.systemDefault()).toInstant()));
        }

        return example;
    }

    public String getCreateTimeStart() {
        return createTimeStart;
    }

    public void setCreateTimeStart(String createTimeStart) {
        this.createTimeStart = createTimeStart;
    }

    public String getCreateTimeEnd() {
        return createTimeEnd;
    }

    public void setCreateTimeEnd(String createTimeEnd) {
        this.createTimeEnd = createTimeEnd;
    }

    public String getModifyTimeStart() {
        return modifyTimeStart;
    }

    public void setModifyTimeStart(String modifyTimeStart) {
        this.modifyTimeStart = modifyTimeStart;
    }

    public String getModifyTimeEnd() {
        return modifyTimeEnd;
    }

    public void setModifyTimeEnd(String modifyTimeEnd) {
        this.modifyTimeEnd = modifyTimeEnd;
    }

    public String getProcessStartTimeStart() {
        return processStartTimeStart;
    }

    public void setProcessStartTimeStart(String processStartTimeStart) {
        this.processStartTimeStart = processStartTimeStart;
    }

    public String getProcessStartTimeEnd() {
        return processStartTimeEnd;
    }

    public void setProcessStartTimeEnd(String processStartTimeEnd) {
        this.processStartTimeEnd = processStartTimeEnd;
    }

    public String getProcessEndTimeStart() {
        return processEndTimeStart;
    }

    public void setProcessEndTimeStart(String processEndTimeStart) {
        this.processEndTimeStart = processEndTimeStart;
    }

    public String getProcessEndTimeEnd() {
        return processEndTimeEnd;
    }

    public void setProcessEndTimeEnd(String processEndTimeEnd) {
        this.processEndTimeEnd = processEndTimeEnd;
    }

    public String getFinishTimeStart() {
        return finishTimeStart;
    }

    public void setFinishTimeStart(String finishTimeStart) {
        this.finishTimeStart = finishTimeStart;
    }

    public String getFinishTimeEnd() {
        return finishTimeEnd;
    }

    public void setFinishTimeEnd(String finishTimeEnd) {
        this.finishTimeEnd = finishTimeEnd;
    }

    /** getter */
    public Long getExportTaskId() {
        return exportTaskId;
    }

    /** setter */
    public void setExportTaskId(Long exportTaskId) {
        this.exportTaskId = exportTaskId;
    }

    /** getter */
    public String getFileName() {
        return fileName;
    }

    /** setter */
    public void setFileName(String fileName) {
        this.fileName = fileName == null ? null : fileName.trim();
    }

    /** getter */
    public Integer getFileDownloadClickTimes() {
        return fileDownloadClickTimes;
    }

    /** setter */
    public void setFileDownloadClickTimes(Integer fileDownloadClickTimes) {
        this.fileDownloadClickTimes = fileDownloadClickTimes;
    }

    /** getter */
    public Integer getFileDownloadFinishTimes() {
        return fileDownloadFinishTimes;
    }

    /** setter */
    public void setFileDownloadFinishTimes(Integer fileDownloadFinishTimes) {
        this.fileDownloadFinishTimes = fileDownloadFinishTimes;
    }

    /** getter */
    public String getFileUrl() {
        return fileUrl;
    }

    /** setter */
    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl == null ? null : fileUrl.trim();
    }

    /** getter */
    public String getLoadDataInterface() {
        return loadDataInterface;
    }

    /** setter */
    public void setLoadDataInterface(String loadDataInterface) {
        this.loadDataInterface = loadDataInterface == null ? null : loadDataInterface.trim();
    }

    /** getter */
    public String getLoadDataInterfaceParams() {
        return loadDataInterfaceParams;
    }

    /** setter */
    public void setLoadDataInterfaceParams(String loadDataInterfaceParams) {
        this.loadDataInterfaceParams = loadDataInterfaceParams == null ? null : loadDataInterfaceParams.trim();
    }

    /** getter */
    public Long getCreator() {
        return creator;
    }

    /** setter */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /** getter */
    public Date getCreateTime() {
        return createTime;
    }

    /** setter */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /** getter */
    public Date getModifyTime() {
        return modifyTime;
    }

    /** setter */
    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    /** getter */
    public Date getProcessStartTime() {
        return processStartTime;
    }

    /** setter */
    public void setProcessStartTime(Date processStartTime) {
        this.processStartTime = processStartTime;
    }

    /** getter */
    public Date getProcessEndTime() {
        return processEndTime;
    }

    /** setter */
    public void setProcessEndTime(Date processEndTime) {
        this.processEndTime = processEndTime;
    }

    /** getter */
    public Integer getTaskStatus() {
        return taskStatus;
    }

    /** setter */
    public void setTaskStatus(Integer taskStatus) {
        this.taskStatus = taskStatus;
    }

    /** getter */
    public String getTaskStatusRemark() {
        return taskStatusRemark;
    }

    /** setter */
    public void setTaskStatusRemark(String taskStatusRemark) {
        this.taskStatusRemark = taskStatusRemark == null ? null : taskStatusRemark.trim();
    }

    /** getter */
    public Integer getNotifyType() {
        return notifyType;
    }

    /** setter */
    public void setNotifyType(Integer notifyType) {
        this.notifyType = notifyType;
    }

    /** getter */
    public String getNotifyUser() {
        return notifyUser;
    }

    /** setter */
    public void setNotifyUser(String notifyUser) {
        this.notifyUser = notifyUser == null ? null : notifyUser.trim();
    }

    /** getter */
    public Integer getNotified() {
        return notified;
    }

    /** setter */
    public void setNotified(Integer notified) {
        this.notified = notified;
    }
}
